 <div class="w-content wrap-newsletter clearfix">
    <p class="txt-newsletter">Tilmeld dig vores nyhedsbrev og få 5% i rabat på alle onlinekøb. Vi udsender nyhedsbrev 1-2 gange om måneden.</p>
    <form action="<?php echo str_replace('&', '&amp;', $action); ?>" method="post" enctype="multipart/form-data" id="newsletterForm">
        <input placeholder="Indtast dit navn....." id="subscriber_name" name="subscriber_name" class="txtInput ipname">
        <input placeholder="Indtast din e-mail adresse....." id="subscriber_email" name="subscriber_email" class="txtInput ipmail">
        <a href="#" id="subscriber_button1" class="btn btnTilmeld">Tilmeld</a>
        <a href="#" id="unsubscriber_button1" class="btn btnAfmeld">Afmeld </a>
    </form>
</div>

<script type="text/javascript">
	var mail_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{2,6})+$/;

	jQuery('#subscriber_button1').on('click', function(event){
		event.preventDefault();						
		
		if(jQuery('#subscriber_name').val() == ''){
			//showPopup('Navn er ugyldig. Indtast en gyldig navn.');
            jQuery('#subscriber_name').addClass('errorField');

            return false;
		}
		
		if(!mail_filter.test(jQuery('#subscriber_email').val())){
			//showPopup('E-mailen er ugyldig. Indtast en gyldig e-mail.');
            jQuery('#subscriber_email').addClass('errorField');

            return false;
		}

        jQuery.ajax({
            type: "POST",
            url: "<?php echo $subscriber_url; ?>",
            data: {'email': jQuery('#subscriber_email').val(), 'name': jQuery('#subscriber_name').val()},
            dataType: "text",
            async: false,
            success: function(data, text, request) {
                showPopup(data);

            },
            complete: function(xhr, status) {
            }
        });
	});

	jQuery('#unsubscriber_button1').on('click', function(event){
		event.preventDefault();
		
		if(!mail_filter.test(jQuery('#subscriber_email').val())){
			//showPopup('E-mailen er ugyldig. Indtast en gyldig e-mail.');
            jQuery('#subscriber_email').addClass('errorField');

			return false;
		}

        jQuery.ajax({
            type: "POST",
            url: "<?php echo $unsubscriber_url; ?>",
            data: {email: jQuery('#subscriber_email').val()},
            dataType: "text",
            async: false,
            success: function(data, text, request) {
                showPopup(data);
            },
            complete: function(xhr, status) {
            }
        });
	});
</script>
